import {EchartLayer} from "./echartLayer/EchartLayer";
import {options} from "./echartLayer/options";
import {WindFarm} from "./wind/WindFarm";
import {PointAttack} from "./pointAttack/PointAttack";

export class ManageEcharts{
  _saveEchartsLayer = new Map();
  _viewManage = null;
  constructor(viewManage){
    this._viewManage = viewManage;
  }





  applyMigration(key,site,moveLines){
    let saveEchartsLayer = this._saveEchartsLayer;
    if (saveEchartsLayer.has(key)) {
      console.error("该key已经申请过了", key);
      return;
    }
    let option = options.migration(site,moveLines);
    let chart = new EchartLayer(this._viewManage,option);
    saveEchartsLayer.set(key, chart);
  }

  /**
   * 闪烁的点位
   * @param mapId
   * @param key
   * @param data
   */
  applyFlashingPoint(key, data, itemColor = '#f4e925', symbol = "circle", brushType = "stroke") {
    let saveEchartsLayer = this._saveEchartsLayer;
    if (saveEchartsLayer.has(key)) {
      console.error("该key已经申请过了", key);
      return;
    }
    let option =options.flashingPoint(data, itemColor, symbol, brushType )
    let chart = new EchartLayer(this._viewManage,option);
    saveEchartsLayer.set(key, chart);
  }


  applyWindFarm(key, windData) {
    let saveEchartsLayer = this._saveEchartsLayer;
    if (saveEchartsLayer.has(key)) {
      console.error("该key已经申请过了", key);
      return;
    }
    let windFarm = new WindFarm(this._viewManage, windData);
    let chart = windFarm.getChart();
    saveEchartsLayer.set(key, chart);
  }


  applyPointAttack(key,data){
    let saveEchartsLayer = this._saveEchartsLayer;
    if (saveEchartsLayer.has(key)) {
      console.error("该key已经申请过了", key);
      return;
    }
    let pointAttack =  new PointAttack(this._viewManage,data);
    let chart = pointAttack.getChart();
    saveEchartsLayer.set(key, chart);
  }


  removeEcharLayer (key) {
    let saveEchartsLayer = this._saveEchartsLayer;
    if (saveEchartsLayer.has(key)) {
      saveEchartsLayer.get(key).removeLayer();
      saveEchartsLayer.delete(key);
    }
  }
}
